﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Cs期中作业
{
    public partial class 入住查询 : Form
    {
        public 入住查询()
        {
            InitializeComponent();
        }
        private void 入住查询_Load(object sender, EventArgs e)
        {
            Gen.GetPrivateProfileString("Host", "Server", "localhost", ipS, 255, @".\config.ini");
            Gen.GetPrivateProfileString("SQL", "Database", "Dorm", dbS, 255, @".\config.ini");
            Gen.GetPrivateProfileString("SQL", "CheckInSheet", "Dorm", CheckInShS, 255, @".\config.ini");
            Gen.GetPrivateProfileString("SQL", "UserName", "", sqlUserS, 255, @".\config.ini");
            Gen.GetPrivateProfileString("SQL", "Password", "", sqlPwS, 255, @".\config.ini");
            ip = ipS.ToString();
            db = dbS.ToString();
            CheckInSh = CheckInShS.ToString();
            sqlUser = sqlUserS.ToString();
            sqlPw = sqlPwS.ToString();
            connString = "Data Source=" + ip + ";Initial Catalog=" + db + ";Persist Security Info=True;User ID=" + sqlUser + ";Password=" + sqlPw;
            

        }
        StringBuilder ipS = new StringBuilder();
        StringBuilder dbS = new StringBuilder();
        StringBuilder CheckInShS = new StringBuilder();
        StringBuilder sqlUserS = new StringBuilder();
        StringBuilder sqlPwS = new StringBuilder();
        string ip, db, CheckInSh, sqlUser, sqlPw, connString;

        private void button1_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(connString);
            string sql = "select * from " + CheckInSh + " where 楼号 like'"+textBox1.Text+"' and 宿舍号 like "+textBox2.Text+"'";
            SqlDataAdapter dataAdapter = new SqlDataAdapter(sql, con);
            DataSet dataSet = new DataSet("宿舍");
            dataAdapter.Fill(dataSet);
            dataGridView1.DataSource = dataSet.Tables[0];
            dataGridView1.Columns[0].HeaderText = "序号";
            dataGridView1.Columns[1].HeaderText = "楼号";
            dataGridView1.Columns[2].HeaderText = "宿舍号";
            dataGridView1.Columns[3].HeaderText = "班级";
            dataGridView1.Columns[4].HeaderText = "学号";
            dataGridView1.Columns[5].HeaderText = "姓名";
            dataGridView1.Columns[6].HeaderText = "入住日期";
            this.Size = new Size(464, 355);
        }

        private void button4_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(connString); 
            string sql = "select * from " + CheckInSh + " where 楼号 like'"+textBox1.Text+"' and 宿舍号 like '"+textBox2.Text+"'";
            SqlDataAdapter dataAdapter = new SqlDataAdapter(sql, con);
            DataSet dataSet = new DataSet("宿舍");
            dataAdapter.Fill(dataSet);
            dataGridView1.DataSource = dataSet.Tables[0];
            dataGridView1.Columns[0].HeaderText = "序号";
            dataGridView1.Columns[1].HeaderText = "楼号";
            dataGridView1.Columns[2].HeaderText = "宿舍号";
            dataGridView1.Columns[3].HeaderText = "班级";
            dataGridView1.Columns[4].HeaderText = "学号";
            dataGridView1.Columns[5].HeaderText = "姓名";
            dataGridView1.Columns[6].HeaderText = "入住日期";
            this.Size = new Size(464, 355);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}